﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;

public class ExvelToCsvEditor
{
    [MenuItem("Assets/My Tools/ExcelToCsv", false,1)]
    public static void ToCsv()
    {
       string[] strs = Selection.assetGUIDs;
       var curPath = System.IO.Directory.GetCurrentDirectory();
       string path = AssetDatabase.GUIDToAssetPath(strs[0]);
       string allpath = curPath + "\\" + path;
       allpath = allpath.Replace("/", "\\");
       var strArry = allpath.Split('\\');
       var fileStr = strArry[strArry.Length - 1];
       var str = allpath.Replace("\\" + fileStr, "");
       var fileType = fileStr.Substring(fileStr.Length - 5);
       if (fileType!=".xlsx")
       {
           Debug.LogError("未选中指定的文件或文件类型错误");
           return;
       }
       EdtUtil.RunCmd("excel2csv", fileStr, str);
       AssetDatabase.Refresh();
       Debug.Log("文件" + fileStr + "已拆分");
    }

}
